package org.bmi.gwt.examples.transaction.shared;

import java.util.Date;

import org.bmi.gwt.mi.shared.MiObject;

import com.google.gwt.dom.client.Document;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;

public class MethodsTestObject implements MiObject
{
	private String str;

	public MethodsTestObject(String str)
	{
		this.str = str;
	}

	/**
	 * Prints the provided string in a popup alert, and return the current date.
	 * 
	 * @param str
	 * @return
	 */
	public Date returnDate(String str)
	{
		print(this.str + " --> " + str);
		return new Date();
	}

	/**
	 * Prints in a popup alert the provided date.
	 * 
	 * @param date
	 */
	public void provideDate(Date date)
	{
		print(this.str + " --> " + date);
	}

	/**
	 * Returns a copy of the object.
	 * 
	 * @return
	 */
	public MethodsTestObject getObjectCopy()
	{
		return new MethodsTestObject("copy of " + this.str);
	}

	/**
	 * Returns a wrapped copy of the provided object.
	 * 
	 * @param obj
	 * @return
	 */
	public MethodsTestObject wrap(MethodsTestObject obj)
	{
		return new MethodsTestObject("wrap of " + obj.str);
	}

	private void print(String text)
	{
		RootPanel rootPanel = RootPanel.get();
		Element body = rootPanel.getElement();

		body.appendChild(Document.get().createBRElement());
		body.appendChild(Document.get().createTextNode(text));
	}
}
